package com.muyu.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.product.domain.ProjectSkuInfo;
import com.muyu.product.domain.req.ProjectSkuInfoQueryReq;
import com.muyu.product.domain.req.ProjectSkuInfoSaveReq;
import com.muyu.product.domain.req.ProjectSkuInfoEditReq;
import com.muyu.product.service.ProjectSkuInfoService;
import com.muyu.common.core.web.page.TableDataInfo;

/**
 * 商品SKUController
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Api(tags = "商品SKU")
@RestController
@RequestMapping("/sku")
public class ProjectSkuInfoController extends BaseController {
    @Autowired
    private ProjectSkuInfoService projectSkuInfoService;

    /**
     * 查询商品SKU列表
     */
    @ApiOperation("获取商品SKU列表")
    @RequiresPermissions("product:sku:list")
    @GetMapping("/list")
    public Result<TableDataInfo<ProjectSkuInfo>> list(ProjectSkuInfoQueryReq projectSkuInfoQueryReq) {
        startPage();
        List<ProjectSkuInfo> list = projectSkuInfoService.list(ProjectSkuInfo.queryBuild(projectSkuInfoQueryReq));
        return getDataTable(list);
    }

    /**
     * 导出商品SKU列表
     */
    @ApiOperation("导出商品SKU列表")
    @RequiresPermissions("product:sku:export")
    @Log(title = "商品SKU", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectSkuInfo projectSkuInfo) {
        List<ProjectSkuInfo> list = projectSkuInfoService.list(projectSkuInfo);
        ExcelUtil<ProjectSkuInfo> util = new ExcelUtil<ProjectSkuInfo>(ProjectSkuInfo.class);
        util.exportExcel(response, list, "商品SKU数据");
    }

    /**
     * 获取商品SKU详细信息
     */
    @ApiOperation("获取商品SKU详细信息")
    @RequiresPermissions("product:sku:query")
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    public Result<ProjectSkuInfo> getInfo(@PathVariable("id") Long id) {
        return Result.success(projectSkuInfoService.getById(id));
    }

    /**
     * 新增商品SKU
     */
    @RequiresPermissions("product:sku:add")
    @Log(title = "商品SKU", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增商品SKU")
    public Result<String> add(@RequestBody ProjectSkuInfoSaveReq projectSkuInfoSaveReq) {
        return toAjax(projectSkuInfoService.save(ProjectSkuInfo.saveBuild(projectSkuInfoSaveReq)));
    }

    /**
     * 修改商品SKU
     */
    @RequiresPermissions("product:sku:edit")
    @Log(title = "商品SKU", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}")
    @ApiOperation("修改商品SKU")
    public Result<String> edit(@PathVariable Long id, @RequestBody ProjectSkuInfoEditReq projectSkuInfoEditReq) {
        return toAjax(projectSkuInfoService.updateById(ProjectSkuInfo.editBuild(id,projectSkuInfoEditReq)));
    }

    /**
     * 删除商品SKU
     */
    @RequiresPermissions("product:sku:remove")
    @Log(title = "商品SKU", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除商品SKU")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
    public Result<String> remove(@PathVariable List<Long> ids) {
        return toAjax(projectSkuInfoService.removeBatchByIds(ids));
    }
}
